1
bash
This code uses a regular expression to extract an email address from a string, demonstrating regex-based pattern matching and extraction in Bash.
string="Hello, my email is user@example.com" # Use regex to match an email address if [[ $string =~ [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} ]]; then echo "Email found: ${BASH_REMATCH[0]}" else echo "No email found." fi
bash internaldata manipulationsstring manipulation and expansionsregular expressions (regex)